<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>08-响应式数据</title>
    <script src="lib/react/react.development.js"></script>
    <script src="lib/react/react-dom.development.js"></script>
    <script src="lib/babel.min.js"></script>
  </head>
  <body>
    <div id="root"></div>
    <script type="text/babel">
      class HelloWorld extends React.Component {
        constructor() {
          super();
          console.log("1. 构造函数");
          this.state = {
            nowTime: new Date().getTime(),
            count: 0,
          };
        }
        componentDidMount() {
          console.log("3. 渲染完成");
          setTimeout(() => {
            this.setState({
              count: this.state.count + 1, // 1
            });
            console.log("this.state.count_1", this.state.count);
            this.setState({
              count: this.state.count + 1, // 2
            });
            this.setState({
              nowTime: "新时间",
            });
            console.log('this.state.count_2',this.state.count); // 2?
          }, 3000);
        }
        componentWillUnMount() {
          console.log("组件即将销毁...");
        }
        render() {
          console.log("2. render...");
          return (
            <div>
              <h2>倒计时</h2>
              <span>{this.state.nowTime}</span>
            </div>
          );
        }
      }
      ReactDOM.render(<HelloWorld />, document.getElementById("root"));
    </script>
  </body>
</html>
